<template>
	<view class="rateManage">
		<nav-bars title="佣金比例"></nav-bars>
		<view class="content">
			<view class="allBox">
				<view class="rateBox">
					<input type="text" value="" v-model="rate" placeholder="请输入订单佣金比例" />
				</view>
				<text>订单佣金范围为{{rateInfo.rate_min}}-{{rateInfo.rate_max}}%</text>
			</view>
			<view class="btn" @click="saveSet">保存</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				rate:'',
				rateInfo:{}
			}
		},
		onLoad() {
			this.getRateDetail()
		},
		methods:{
			// 获取订单佣金详情
			getRateDetail(){
				let role = this.$store.state.index.role;
				let sid = this.$store.state.index.sid;
				let params = {
					partner_id:sid,
					partner_type:role
				}
				this.$api.getOrderRate(params).then(res=>{
					if(res.code==1){
						this.rateInfo = res.data;
						this.rate = res.data.non_standard_order_rate
					}
				})
			},
			
			// 保存设置
			saveSet(){
				if(this.rate*1>this.rateInfo.rate_max || this.rate*1<this.rateInfo.rate_min){
					uni.showToast({
						title:`佣金范围为 ${this.rateInfo.rate_min}-${this.rateInfo.rate_max}%`,
						icon:'none'
					})
					return
				}
				let role = this.$store.state.index.role;
				let params = {
					rate_id:this.rateInfo.id,
					non_standard_order_rate:this.rate,
					partner_type:role
				}
				this.$api.setOrderRate(params).then(res=>{
					if(res.code==1){
						uni.showToast({
							title:'保存成功',
							icon:'success'
						})
						this.getRateDetail()
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
	page{height: 100%;}
	.rateManage{
		height: 100%;
		background-color: #fff;
		.content{
			display: flex;
			flex-direction: column;
			align-items: center;
			.allBox{
				display: flex;
				flex-direction: column;
				align-items: center;
				margin: 380rpx auto 120rpx;
			}
			.rateBox{
				width: 510rpx;
				height: 80rpx;
				border: 2rpx solid #ccc;
				border-radius: 10rpx;
				margin-bottom: 30rpx;
				input{
					width: 100%;
					height: 100%;
					padding: 0 20rpx;
					line-height: 80rpx;
				}
			}
			.btn{
				height: 80rpx;
				display: inline-block;
				padding: 0 140rpx;
				line-height: 80rpx;
				border-radius: 40rpx;
				background-color: #C1A66C;
				font: 500 32rpx/80rpx PingFang SC;
				color: #fff;
			}
		}
	}
</style>
